home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** FSSpec compatibility functions.
- **
- ** by Jim Luther, Apple Developer Technical Support
- **
- ** File: FSpCompat.c
- **
- ** Copyright © 1992-1994 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes.
- */
-
- #ifndef __FSPCOMPAT__
- #include "FSpCompat.h"
- #endif
-
- /*****************************************************************************/
-
- /* local constants */
-
- enum {
- gestaltBugFixAttrsTwo = 'bugy',
- gestaltFSpExchangeFilesCompatibilityFix = 26,
- gestaltBugFixAttrsThree = 'bugx',
- gestaltFSpCreateScriptSupportFix = 1
- };
-
- /*****************************************************************************/
-
- /* static prototypes */
-
- static Boolean FSHasFSSpecCalls(void);
-
- static Boolean QTHasFSSpecCalls(void);
-
- static Boolean HasFSpExchangeFilesCompatibilityFix(void);
-
- static Boolean HasFSpCreateScriptSupportFix(void);
-
- static OSErr GenerateUniqueName(short volume,
- long *startSeed,
- long dir1,
- long dir2,
- StringPtr uniqueName);
-
- /*****************************************************************************/
-
- /* FSHasFSSpecCalls returns true if the file system provides FSSpec calls. */
-
- static Boolean FSHasFSSpecCalls(void)
- {
- long response;
- static Boolean tested = false;
- static Boolean result = false;
-
- if (!tested)
- {
- tested = true;
- if (Gestalt(gestaltFSAttr, &response) == noErr)
- {
- result = ((response & (1L << gestaltHasFSSpecCalls)) != 0);
- }
- }
- return (result);
- }
-
- /*****************************************************************************/
-
- /* QTHasFSSpecCalls returns true if QuickTime provides FSSpec calls */
- /* except for FSpExchangeFiles. */
-
- static Boolean QTHasFSSpecCalls(void)
- {
- long response;
- static Boolean tested = false;
- static Boolean result = false;
-
- if (!tested)
- {
- tested = true;
- result = (Gestalt(gestaltQuickTime, &response) == noErr);
- }
- return (result);
- }
-
- /*****************************************************************************/
-
- /* HasFSpExchangeFilesCompatibilityFix returns true if FSpExchangeFiles */
- /* compatibility code has been fixed in system software. */
-
- Boolean HasFSpExchangeFilesCompatibilityFix(void)
- {
- long response;
- static Boolean tested = false;
- static Boolean result = false;
-
- if (!tested)
- {
- tested = true;
- if (Gestalt(gestaltBugFixAttrsTwo, &response) == noErr)
- {
- result = ((response & (1L << gestaltFSpExchangeFilesCompatibilityFix)) != 0);
- }
- }
- return (result);
- }
-
- /*****************************************************************************/
-
- /* HasFSpCreateScriptSupportFix returns true if FSpCreate and */
- /* FSpCreateResFile have been fixed in system software to correctly set */
- /* the scriptCode in the volume's catalog. */
-
- Boolean HasFSpCreateScriptSupportFix(void)
- {
- long response;
- static Boolean tested = false;
- static Boolean result = false;
-
- if (!tested)
- {
- if (Gestalt(gestaltBugFixAttrsThree, &response) == noErr)
- {
- result = ((response & (1L << gestaltFSpCreateScriptSupportFix)) != 0);
- }
- }
- return (result);
- }
-
- /*****************************************************************************/
-
- /*
- ** File Manager FSp calls
- */
-
- /*****************************************************************************/
-
- pascal OSErr FSMakeFSSpecCompat(short vRefNum,
- long dirID,
- ConstStr255Param fileName,
- FSSpecPtr spec)
- {
- Boolean isDirectory;
-
- /* Let the file system create the FSSpec if it can since it does the job */
- /* much more efficiently than I can. */
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSMakeFSSpec(vRefNum, dirID, fileName, spec));
- else
- return (GetObjectLocation(vRefNum, dirID, (StringPtr)fileName,
- &(spec->vRefNum), &(spec->parID), spec->name,
- &isDirectory));
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpOpenDFCompat(const FSSpec *spec,
- char permission,
- short *refNum)
- {
- OSErr result;
- HParamBlockRec pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpOpenDF(spec, permission, refNum));
- else
- {
- pb.ioParam.ioVRefNum = spec->vRefNum;
- pb.fileParam.ioDirID = spec->parID;
- pb.ioParam.ioNamePtr = (StringPtr) &(spec->name);
- pb.ioParam.ioVersNum = 0;
- pb.ioParam.ioPermssn = permission;
- pb.ioParam.ioMisc = nil;
- result = PBHOpenSync(&pb); /* OpenDF not supported by System 6, so use Open */
- *refNum = pb.ioParam.ioRefNum;
- return (result);
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpOpenRFCompat(const FSSpec *spec,
- char permission,
- short *refNum)
- {
- OSErr result;
- HParamBlockRec pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpOpenRF(spec, permission, refNum));
- else
- {
- pb.ioParam.ioVRefNum = spec->vRefNum;
- pb.fileParam.ioDirID = spec->parID;
- pb.ioParam.ioNamePtr = (StringPtr) &(spec->name);
- pb.ioParam.ioVersNum = 0;
- pb.ioParam.ioPermssn = permission;
- pb.ioParam.ioMisc = nil;
- result = PBHOpenRFSync(&pb);
- *refNum = pb.ioParam.ioRefNum;
- return (result);
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpCreateCompat(const FSSpec *spec,
- OSType creator,
- OSType fileType,
- ScriptCode scriptTag)
- {
- OSErr result;
- UniversalFMPB pb;
-
- if ((FSHasFSSpecCalls() || QTHasFSSpecCalls()) && HasFSpCreateScriptSupportFix())
- return (FSpCreate(spec, creator, fileType, scriptTag));
- else
- {
- pb.hPB.fileParam.ioVRefNum = spec->vRefNum;
- pb.hPB.fileParam.ioDirID = spec->parID;
- pb.hPB.fileParam.ioNamePtr = (StringPtr) &(spec->name);
- pb.hPB.fileParam.ioFVersNum = 0;
- result = PBHCreateSync(&(pb.hPB));
- if (result == noErr)
- {
- /* get info on created item */
- pb.ciPB.hFileInfo.ioFDirIndex = 0;
- result = PBGetCatInfoSync(&(pb.ciPB));
- if (result == noErr)
- {
- /* Set fdScript in FXInfo */
- /* The negative script constants (smSystemScript, smCurrentScript, and smAllScripts) */
- /* don't make sense on disk, so only use scriptTag if scriptTag >= smRoman */
- /* (smRoman is 0). fdScript is valid if high bit is set (see IM-6, page 9-38) */
- pb.ciPB.hFileInfo.ioFlXFndrInfo.fdScript = (scriptTag >= smRoman) ?
- ((char)scriptTag | (char)0x80) :
- (smRoman);
- /* Set creator/fileType */
- pb.ciPB.hFileInfo.ioFlFndrInfo.fdCreator = creator;
- pb.ciPB.hFileInfo.ioFlFndrInfo.fdType = fileType;
- /* Restore ioDirID field in pb which was changed by PBGetCatInfo */
- pb.ciPB.hFileInfo.ioDirID = spec->parID;
- result = PBSetCatInfoSync(&(pb.ciPB));
- }
- }
- return (result);
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpDirCreateCompat(const FSSpec *spec,
- ScriptCode scriptTag,
- long *createdDirID)
- {
- OSErr result;
- UniversalFMPB pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpDirCreate(spec, scriptTag, createdDirID));
- else
- {
- pb.hPB.fileParam.ioVRefNum = spec->vRefNum;
- pb.hPB.fileParam.ioDirID = spec->parID;
- pb.hPB.fileParam.ioNamePtr = (StringPtr) &(spec->name);
- result = PBDirCreateSync(&(pb.hPB));
- *createdDirID = pb.hPB.fileParam.ioDirID;
- if (result == noErr)
- {
- /* get info on created item */
- pb.ciPB.dirInfo.ioFDirIndex = 0;
- pb.ciPB.dirInfo.ioDrDirID = spec->parID;
- result = PBGetCatInfoSync(&(pb.ciPB));
- if (result == noErr)
- {
- /* Set frScript in DXInfo */
- /* The negative script constants (smSystemScript, smCurrentScript, and smAllScripts) */
- /* don't make sense on disk, so only use scriptTag if scriptTag >= smRoman */
- /* (smRoman is 0). frScript is valid if high bit is set (see IM-6, page 9-38) */
- pb.ciPB.dirInfo.ioDrFndrInfo.frScript = (scriptTag >= smRoman) ?
- ((char)scriptTag | (char)0x80) :
- (smRoman);
- /* Restore ioDirID field in pb which was changed by PBGetCatInfo */
- pb.ciPB.dirInfo.ioDrDirID = spec->parID;
- result = PBSetCatInfoSync(&(pb.ciPB));
- }
- }
- return (result);
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpDeleteCompat(const FSSpec *spec)
- {
- HParamBlockRec pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpDelete(spec));
- else
- {
- pb.ioParam.ioVRefNum = spec->vRefNum;
- pb.fileParam.ioDirID = spec->parID;
- pb.ioParam.ioNamePtr = (StringPtr) &(spec->name);
- pb.ioParam.ioVersNum = 0;
- return (PBHDeleteSync(&pb));
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpGetFInfoCompat(const FSSpec *spec,
- FInfo *fndrInfo)
- {
- OSErr result;
- HParamBlockRec pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpGetFInfo(spec, fndrInfo));
- else
- {
- pb.fileParam.ioVRefNum = spec->vRefNum;
- pb.fileParam.ioDirID = spec->parID;
- pb.fileParam.ioNamePtr = (StringPtr) &(spec->name);
- pb.fileParam.ioFVersNum = 0;
- pb.fileParam.ioFDirIndex = 0;
- result = PBHGetFInfoSync(&pb);
- *fndrInfo = pb.fileParam.ioFlFndrInfo;
- return (result);
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpSetFInfoCompat(const FSSpec *spec,
- const FInfo *fndrInfo)
- {
- OSErr result;
- HParamBlockRec pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpSetFInfo(spec, fndrInfo));
- else
- {
- pb.fileParam.ioVRefNum = spec->vRefNum;
- pb.fileParam.ioDirID = spec->parID;
- pb.fileParam.ioNamePtr = (StringPtr) &(spec->name);
- pb.fileParam.ioFVersNum = 0;
- pb.fileParam.ioFDirIndex = 0;
- result = PBHGetFInfoSync(&pb);
- if (result == noErr)
- {
- pb.fileParam.ioFlFndrInfo = *fndrInfo;
- pb.fileParam.ioDirID = spec->parID;
- result = PBHSetFInfoSync(&pb);
- }
- return (result);
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpSetFLockCompat(const FSSpec *spec)
- {
- HParamBlockRec pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpSetFLock(spec));
- else
- {
- pb.fileParam.ioVRefNum = spec->vRefNum;
- pb.fileParam.ioDirID = spec->parID;
- pb.fileParam.ioNamePtr = (StringPtr) &(spec->name);
- pb.fileParam.ioFVersNum = 0;
- return (PBHSetFLockSync(&pb));
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpRstFLockCompat(const FSSpec *spec)
- {
- HParamBlockRec pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpRstFLock(spec));
- else
- {
- pb.fileParam.ioVRefNum = spec->vRefNum;
- pb.fileParam.ioDirID = spec->parID;
- pb.fileParam.ioNamePtr = (StringPtr) &(spec->name);
- pb.fileParam.ioFVersNum = 0;
- return (PBHRstFLockSync(&pb));
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpRenameCompat(const FSSpec *spec,
- ConstStr255Param newName)
- {
- HParamBlockRec pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpRename(spec, newName));
- else
- {
- pb.ioParam.ioVRefNum = spec->vRefNum;
- pb.fileParam.ioDirID = spec->parID;
- pb.ioParam.ioNamePtr = (StringPtr) &(spec->name);
- pb.ioParam.ioVersNum = 0;
- pb.ioParam.ioMisc = (Ptr) newName;
- return (PBHRenameSync(&pb));
- }
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpCatMoveCompat(const FSSpec *source,
- const FSSpec *dest)
- {
- CMovePBRec pb;
-
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpCatMove(source, dest));
- else
- {
- /* source and destination volume must be the same */
- if (source->vRefNum != dest->vRefNum)
- return (paramErr);
-
- pb.ioNamePtr = (StringPtr) &(source->name);
- pb.ioVRefNum = source->vRefNum;
- pb.ioDirID = source->parID;
- pb.ioNewDirID = dest->parID;
- pb.ioNewName = (StringPtr) &(dest->name);
- return (PBCatMoveSync(&pb));
- }
- }
-
- /*****************************************************************************/
-
- /* GenerateUniqueName generates a name that is unique in both dir1 and dir2 */
- /* on the specified volume. Ripped off from Feldman's code. */
-
- static OSErr GenerateUniqueName(short volume,
- long *startSeed,
- long dir1,
- long dir2,
- StringPtr uniqueName)
- {
- OSErr error = noErr;
- long i;
- CInfoPBRec cinfo;
-
- cinfo.hFileInfo.ioVRefNum = volume;
- cinfo.hFileInfo.ioFDirIndex = 0;
- cinfo.hFileInfo.ioNamePtr = uniqueName;
-
- while (error != fnfErr) {
- (*startSeed)++;
- cinfo.hFileInfo.ioNamePtr[0] = 8;
- for (i = 1; i <= 8; i++)
- cinfo.hFileInfo.ioNamePtr[i] = "0123456789ABCDEF"[((*startSeed >> ((8-i)*4)) & 0xf)];
- cinfo.hFileInfo.ioDirID = dir1;
- error = fnfErr;
- for (i = 1; i <= 2; i++) {
- error = error & PBGetCatInfoSync(&cinfo);
- cinfo.hFileInfo.ioDirID = dir2;
- if ((error != fnfErr) && (error != noErr))
- return (error);
- }
- }
- return (noErr);
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpExchangeFilesCompat(const FSSpec *source,
- const FSSpec *dest)
- {
- HParamBlockRec pb;
- CInfoPBRec catInfoSource, catInfoDest;
- OSErr error, error2;
- Str31 unique1, unique2;
- StringPtr unique1Ptr, unique2Ptr, swapola;
- GetVolParmsInfoBuffer volInfo;
- long theSeed, temp;
-
- if (FSHasFSSpecCalls() && HasFSpExchangeFilesCompatibilityFix())
- return (FSpExchangeFiles(source, dest));
- else
- {
- /* Make sure the source and destination are on the same volume */
- if (source->vRefNum != dest->vRefNum)
- return (paramErr);
-
- /* Try PBExchangeFiles first since it preserves the file ID reference */
- pb.fidParam.ioNamePtr = (StringPtr) &(source->name);
- pb.fidParam.ioVRefNum = source->vRefNum;
- pb.fidParam.ioDestNamePtr = (StringPtr) &(dest->name);
- pb.fidParam.ioDestDirID = dest->parID;
- pb.fidParam.ioSrcDirID = source->parID;
-
- error = PBExchangeFilesSync(&pb);
-
- /* Note: The compatibility case won't work for files with *Btree control blocks. */
- /* Right now the only *Btree files are created by the system. */
- if (error != noErr)
- {
- pb.ioParam.ioNamePtr = nil;
- pb.ioParam.ioBuffer = (Ptr) &volInfo;
- pb.ioParam.ioReqCount = sizeof(volInfo);
- error2 = PBHGetVolParmsSync(&pb);
-
- /* continue if volume has no fileID support (or no GetVolParms support) */
- if ((error2 == noErr) && (volInfo.vMAttrib & (1<<bHasFileIDs)))
- return (error);
-
- /* Get the catalog information for each file */
- /* and make sure both files are *really* files */
- catInfoSource.hFileInfo.ioVRefNum = source->vRefNum;
- catInfoSource.hFileInfo.ioFDirIndex = 0;
- catInfoSource.hFileInfo.ioNamePtr = (StringPtr) &(source->name);
- catInfoSource.hFileInfo.ioDirID = source->parID;
- catInfoSource.hFileInfo.filler2 = 0;
- error = PBGetCatInfoSync(&catInfoSource);
- if (error != noErr)
- return (error);
- if (catInfoSource.hFileInfo.ioFlAttrib & ioDirMask)
- return (notAFileErr);
-
- catInfoDest.hFileInfo.ioVRefNum = dest->vRefNum;
- catInfoDest.hFileInfo.ioFDirIndex = 0;
- catInfoDest.hFileInfo.ioNamePtr = (StringPtr) &(dest->name);
- catInfoDest.hFileInfo.ioDirID = dest->parID;
- catInfoDest.hFileInfo.filler2 = 0;
- error = PBGetCatInfoSync(&catInfoDest);
- if (error != noErr)
- return (error);
- if (catInfoDest.hFileInfo.ioFlAttrib & ioDirMask)
- return (notAFileErr);
-
- /* generate 2 filenames that are unique in both directories */
- theSeed = 0x64666A6C; /* a fine unlikely filename */
- unique1Ptr = (StringPtr)&unique1;
- unique2Ptr = (StringPtr)&unique2;
-
- error = GenerateUniqueName(source->vRefNum, &theSeed, source->parID, dest->parID, unique1Ptr);
- if (error != noErr)
- return (error);
-
- GenerateUniqueName(source->vRefNum, &theSeed, source->parID, dest->parID, unique2Ptr);
- if (error != noErr)
- return (error);
-
- /* rename source to unique1 */
- pb.fileParam.ioNamePtr = (StringPtr) &(source->name);
- pb.ioParam.ioMisc = (Ptr) unique1Ptr;
- error = PBHRenameSync(&pb);
- if (error != noErr)
- return (error);
-
- /* rename dest to unique2 */
- pb.ioParam.ioMisc = (Ptr) unique2Ptr;
- pb.fileParam.ioNamePtr = (StringPtr) &(dest->name);
- pb.fileParam.ioDirID = dest->parID;
- error = PBHRenameSync(&pb);
- if (error != noErr)
- goto error2; /* back out gracefully by renaming unique1 back to source */
-
- /* If files are not in same directory, swap their locations */
- if (source->parID != dest->parID)
- {
- /* move source file to dest directory */
- pb.copyParam.ioNamePtr = unique1Ptr;
- pb.copyParam.ioNewName = nil;
- pb.copyParam.ioNewDirID = dest->parID;
- pb.copyParam.ioDirID = source->parID;
- error = PBCatMoveSync((CMovePBPtr) &pb);
- if (error != noErr)
- goto error1; /* back out gracefully by renaming both files to original names */
-
- /* move dest file to source directory */
- pb.copyParam.ioNamePtr = unique2Ptr;
- pb.copyParam.ioNewDirID = source->parID;
- pb.copyParam.ioDirID = dest->parID;
- error = PBCatMoveSync((CMovePBPtr) &pb);
- if (error != noErr)
- {
- /* life is very bad. We'll at least try to move source back */
- pb.copyParam.ioNamePtr = unique1Ptr;
- pb.copyParam.ioNewName = nil;
- pb.copyParam.ioNewDirID = source->parID;
- pb.copyParam.ioDirID = dest->parID;
- (void) PBCatMoveSync((CMovePBPtr) &pb); /* ignore errors */
- goto error1; /* back out gracefully by renaming both files to original names */
- }
- }
-
- /* Make unique1Ptr point to file in source->parID */
- /* and unique2Ptr point to file in dest->parID */
- /* This lets us fall through to the rename code below */
- swapola = unique1Ptr;
- unique1Ptr = unique2Ptr;
- unique2Ptr = swapola;
-
- /* At this point, the files are in their new locations (if they were moved) */
- /* Source is named Unique1 (name pointed to by unique2Ptr) and is in dest->parID */
- /* Dest is named Unique2 (name pointed to by unique1Ptr) and is in source->parID */
- /* Need to swap attributes except mod date and swap names */
-
- /* swap the catalog info by re-aiming the CInfoPB's */
- catInfoSource.hFileInfo.ioNamePtr = unique1Ptr;
- catInfoDest.hFileInfo.ioNamePtr = unique2Ptr;
-
- catInfoSource.hFileInfo.ioDirID = source->parID;
- catInfoDest.hFileInfo.ioDirID = dest->parID;
-
- /* Swap the original mod dates with each file */
- temp = catInfoSource.hFileInfo.ioFlMdDat;
- catInfoSource.hFileInfo.ioFlMdDat = catInfoDest.hFileInfo.ioFlMdDat;
- catInfoDest.hFileInfo.ioFlMdDat = temp;
-
- /* Here's the swap (ignore errors) */
- (void) PBSetCatInfoSync(&catInfoSource);
- (void) PBSetCatInfoSync(&catInfoDest);
-
- /* rename unique2 back to dest */
- error1:
- pb.ioParam.ioMisc = (Ptr) &(dest->name);
- pb.fileParam.ioNamePtr = unique2Ptr;
- pb.fileParam.ioDirID = dest->parID;
- (void) PBHRenameSync(&pb); /* ignore errors */
-
- /* rename unique1 back to source */
- error2:
- pb.ioParam.ioMisc = (Ptr) &(source->name);
- pb.fileParam.ioNamePtr = unique1Ptr;
- pb.fileParam.ioDirID = source->parID;
- (void) PBHRenameSync(&pb); /* ignore errors */
- }
- return (error);
- }
- }
-
- /*****************************************************************************/
-
- /*
- ** Resource Manager FSp calls
- */
-
- /*****************************************************************************/
-
- pascal short FSpOpenResFileCompat(const FSSpec *spec,
- SignedByte permission)
- {
- /* ••••• NEED TO MAKE SURE QUICKTIME PROVIDES THIS ONE ••••• */
- if (FSHasFSSpecCalls() || QTHasFSSpecCalls())
- return (FSpOpenResFile(spec, permission));
- else
- return (HOpenResFile(spec->vRefNum, spec->parID, spec->name, permission));
- }
-
- /*****************************************************************************/
-
- pascal void FSpCreateResFileCompat(const FSSpec *spec,
- OSType creator,
- OSType fileType,
- ScriptCode scriptTag)
- {
- OSErr result;
- CInfoPBRec pb;
-
- /* ••••• NEED TO MAKE SURE QUICKTIME PROVIDES THIS ONE ••••• */
- if ((FSHasFSSpecCalls() || QTHasFSSpecCalls()) && HasFSpCreateScriptSupportFix())
- {
- FSpCreateResFile(spec, creator, fileType, scriptTag);
- return;
- }
- else
- {
- HCreateResFile(spec->vRefNum, spec->parID, spec->name);
- if (ResError() == noErr)
- {
- /* get info on created item */
- pb.hFileInfo.ioVRefNum = spec->vRefNum;
- pb.hFileInfo.ioDirID = spec->parID;
- pb.hFileInfo.ioNamePtr = (StringPtr) &(spec->name);
- pb.hFileInfo.ioFDirIndex = 0;
- result = PBGetCatInfoSync(&pb);
- if (result == noErr)
- {
- /* Set fdScript in FXInfo */
- /* The negative script constants (smSystemScript, smCurrentScript, and smAllScripts) */
- /* don't make sense on disk, so only use scriptTag if scriptTag >= smRoman */
- /* (smRoman is 0). fdScript is valid if high bit is set (see IM-6, page 9-38) */
- pb.hFileInfo.ioFlXFndrInfo.fdScript = (scriptTag >= smRoman) ?
- ((char)scriptTag | (char)0x80) :
- (smRoman);
- /* Set creator/fileType */
- pb.hFileInfo.ioFlFndrInfo.fdCreator = creator;
- pb.hFileInfo.ioFlFndrInfo.fdType = fileType;
-
- /* Restore ioDirID field in pb which was changed by PBGetCatInfo */
- pb.hFileInfo.ioDirID = spec->parID;
- result = PBSetCatInfoSync(&pb);
- }
- /* Set ResErr low memory global to result */
- LMSetResErr(result);
- }
- return;
- }
- }
-
- /*****************************************************************************/
-